package com.google.code.scalaxmljaxen

import scala.xml._
import scala.testing.SUnit._

object Tests extends TestConsoleMainX {
  import NodeSeqX._
  
  object NodeSeqXTest extends TestCase("NodeSeqX") {
    def testString(expected: String, xml: NodeSeq, expr: String) {
      val actual = xml.valueOf(expr)
      assertEquals("expecting '" + expected + "', got '" + actual + "'", expected, actual)
    }
    
    def testNumber(expected: Double, xml: NodeSeq, expr: String) {
      val actual = xml.numberValueOf(expr)
      assertEquals("expecting '" + expected + "', got '" + actual + "'", expected, actual)
    }
    
    def testElements() {
      val xml = <a> <b>bb</b> <c>cc</c> </a>
      testString("bb", xml, "b")
      testString("cc", xml, "c")
      testString(" bb cc ", xml, ".")
      testString("bb", xml, "*")      
    }
    
    def testAttributes() {
      val xml = <a> <b id="12">bbb</b> </a>
      testString("bbb", xml, "b[@id = '12']")
      testNumber(12, xml, "b/@id")
    }
    
    def testSimple() {
      assertEquals("bebe", <a>bebe</a>.valueOf("."))
    }
    
    override def runTest() {
      testElements()
      testAttributes()
      testSimple()
    }
  }
  
  val suite = new TestSuite
  suite.addTest(NodeSeqXTest)
}

// vim: set ts=2 sw=2 et:
